function popupCheckCoupon(popupWindow,couponID, couponName, couponPrice)
{
	popupWindow.html('<form id="couponForm"><input type="hidden" id="action" name="action" /><input type="hidden" id="couponID" name="couponID"/><div class="popup1"><div class="popup_title">获取优惠券</div><div id="closeWindow" class="popup_close"><a href="###"><span>关闭窗口</span></a></div></div><div class="popup2"><div style="padding: 5px; font-size: 12px; font-weight: bold;" >您将兑换优惠券'+couponName+'，这将消耗您<span style="color: #E50026; font-weight: bold;">'+couponPrice+'</span>元E币！</div><div class="popup_btns"><input type="button" id="submitGetCoupon" class="btn_1" value="兑换"/>&nbsp;<input type="button" id="cancelGetCoupon" class="btn_5" value="取消"/></div></div><div class="popup3"></div></form>');
	
	$("#couponForm>input[name='action']").attr('value','buy');
	$("#couponID").attr('value',couponID);
	
	$("#submitGetCoupon").click(function()
	{	
		var params = $("#couponForm").serializeArray();
		getCoupon(popupWindow, params);
	});
	
	 $("#cancelGetCoupon").click(function() 
	 {
		 $.unblockUI();
	 });
	   
	 $("#closeWindow>a").click(function() 
	 {
		 $.unblockUI();
	 });
}

function popupCouponResult(popupWindow, couponResult)
{
	popupWindow.html('<div class="popup1"><div class="popup_title">您的优惠券</div></div><div class="popup2"><div class="couponDesc">'+couponResult+'</div><div class="popup_btns"><input type="button" id="cancelCouponResult" class="btn_1" value="确定"/></div></div><div class="popup3"></div>');        
	
	$("#cancelCouponResult").click(function() 
	{
		$.unblockUI();
	});
	
}

function getCoupon(popupWindow, params)
{
	$.ajax(
	{
		type: 'post',
        url: edp_domain_url + 'ajax_coupon/?tiny=1',
        data: params,
		timeout: 5000,
		global:false,
		beforeSend: function()
		{
			$.blockUI(
			{ 
				message: '正在处理...',
			    css: { padding:'5px',color:'#CC0000'}
			});
		},
		error: function()
		{
			$.blockUI(
			{ 
			    message: '添加出错...',
			    css: { padding:'5px',color:'#CC0000'}
			});
		},
		success: function(data)
		{
			popupCouponResult(popupWindow, data);
			$.blockUI(
			{ 
				message: popupWindow,    
				css: 
				{ 
					padding:        0,
					margin:         0,
					top:            '30%', 
	        		left:           '35%', 
					width:          '',
					textAlign:      '', 
					color:          '', 
					border:         '',
					backgroundColor:'',       				
					cursor:         'wait'				        
				 }
			}); 			  			
        }
     });
}
